import React from "react";

class Demo extends React.Component{
    constructor(props){
        super(props);
        this.titleBox = React.createRef();
    }
    render(){
        return(
            <div>
                <h1 className="title" ref={this.titleBox}>hello world</h1>
            </div>
        )
    }
    componentDidMount(){
        console.log("componentDidMount");
        console.log(this);
        console.log(this.titleBox.current);
    }
    componentDidUpdate(){
        console.log("componentDidUpdate");
    }
    componentWillUnmount(){ 
        console.log("componentWillUnmount");
    }
}
const Demo2 = () => {
    const titleBox = React.useRef(null);
    React.useEffect(() => {
        console.log(titleBox.current);
    }, []);
    return(
        <div>
            <h1 className="title" ref={titleBox}>hello world</h1>
        </div>
    )
}
export default Demo2;
